package cn.jolyoulu.adminweb.controller.auth;


import cn.jolyoulu.common.web.security.permission.Permission;
import cn.jolyoulu.common.web.entity.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.jolyoulu.adminweb.entity.bo.LoginBO;
import cn.jolyoulu.adminweb.entity.vo.SysUserInfoVO;
import cn.jolyoulu.adminweb.service.ApiSysUserAuthService;

import java.util.HashMap;

/**
 * 认证
 * @Author LuZhouJin
 * @Date 2023/3/16
 */
@RestController
@RequestMapping("/api/auth")
public class ApiSysUserAuthController {

    @Autowired
    private ApiSysUserAuthService apiSysUserAuthService;

    /**
     * 登录
     */
    @Permission(flag = false)
    @PostMapping("/login")
    public ResultInfo<HashMap<Object, Object>> login(@RequestBody @Validated LoginBO loginBO){
        String token = apiSysUserAuthService.login(loginBO);
        HashMap<Object, Object> res = new HashMap<>();
        res.put("token",token);
        return ResultInfo.success(res);
    }

    /**
     * 登录用户信息
     */
    @Permission(flag = false)
    @GetMapping("/userInfo")
    public ResultInfo<SysUserInfoVO> userInfo(){
        SysUserInfoVO res = apiSysUserAuthService.userInfo();
        return ResultInfo.success(res);
    }

    /**
     * 退出登录
     */
    @Permission(flag = false)
    @GetMapping("/logOut")
    public ResultInfo logOut(){
        apiSysUserAuthService.logOut();
        return ResultInfo.success();
    }
}
